package icu.study.common.entity;

import icu.study.common.security.constant.SystemConstant;

import java.util.Date;

public class Result<T> {
    private Long code;
    private String msg;
    private T data;
    private Date nowTime;

    public Result() {

    }

    public Result(Long code, String msg) {
        this.code = code;
        this.msg = msg;
        this.nowTime = new Date();
    }

    public Result errorCj(String msg) {
        this.code = SystemConstant.RESULT_CODE_NO;
        this.msg = msg;
        this.nowTime = new Date();
        return this;
    }

    public Result error(String msg) {
        this.code = SystemConstant.RESULT_CODE_NOT_AUTH;
        this.msg = msg;
        this.nowTime = new Date();
        return this;
    }

    public Result noVip(String msg) {
        this.code = SystemConstant.RESULT_CODE_NO_VIP;
        this.msg = msg;
        this.nowTime = new Date();
        return this;
    }

    public Result error(String msg, T data) {
        this.code = SystemConstant.RESULT_CODE_NOT_AUTH;
        this.msg = msg;
        this.data = data;
        this.nowTime = new Date();
        return this;
    }

    public Result exception(String msg) {
        this.code = SystemConstant.RESULT_CODE_EXCEPTION;
        this.msg = msg;
        this.nowTime = new Date();
        return this;
    }

    public Result notfound() {
        this.code = SystemConstant.RESULT_CODE_NOT_FOUND;
        this.msg = "没有找到该用户";
        this.nowTime = new Date();
        return this;
    }

    public Result overdue() {
        this.code = SystemConstant.RESULT_CODE_LOGIN_OVERDUE;
        this.msg = "登陆过期";
        this.nowTime = new Date();
        return this;
    }

    public Result noLogin() {
        this.code = SystemConstant.RESULT_CODE_NOT_LOGIN;
        this.msg = "您还没有登陆";
        return this;
    }

    public Result success(String msg, T data) {
        this.code = SystemConstant.RESULT_CODE_SUCCESS_MSG;
        this.msg = msg;
        this.data = data;
        this.nowTime = new Date();
        return this;
    }

    public Result success(T data) {
        this.code = SystemConstant.RESULT_CODE_SUCCESS_MSG_DATA;
        this.msg = "操作成功";
        this.data = data;
        this.nowTime = new Date();
        return this;
    }

    public Result success(String msg) {
        this.code = SystemConstant.RESULT_CODE_SUCCESS_MSG;
        this.msg = msg;
        this.nowTime = new Date();
        return this;
    }

    public Result success() {
        this.code = SystemConstant.RESULT_CODE_SUCCESS;
        this.msg = "操作成功";
        this.nowTime = new Date();
        return this;
    }

    public Result(Long code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.nowTime = new Date();
    }

    public Long getCode() {
        return code;
    }

    public Result<T> setCode(Long code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public Result<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public T getData() {
        return data;
    }

    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }

    public Date getNowTime() {
        return nowTime;
    }

    public void setNowTime(Date nowTime) {
        this.nowTime = nowTime;
    }
}
